using MediatR;
using Microsoft.AspNetCore.Mvc;
using WMS.ErrorCode;
using WMS.WebApiWrite.Application.Command;
using WMS.WebApiWrite.DTO;

namespace WMS.WebApiWrite.Controllers
{
    /// <summary>
    /// 产品信息写操作控制器（新增）
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ProductController> logger;

        /// <summary>
        /// 构造函数，注入MediatR和日志服务
        /// </summary>
        public ProductController(IMediator mediator, ILogger<ProductController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 新增产品信息（货品编号自动生成：HPDH+4位随机数）
        /// </summary>
        /// <param name="productDTO">产品信息DTO</param>
        /// <returns>返回操作结果</returns>
        [HttpPost]
        public async Task<ApiResult<bool>> AddProduct([FromBody] ProductDTO productDTO)
        {
            logger.LogInformation($"开始新增产品信息，产品名称：{productDTO.ProductName}，数据状态：{productDTO.DataStatus}");

            return await mediator.Send(new AddProductCommand
            {
                ProductDTO = productDTO
            });
        }
    }
}

